/**
 * @documention 聊天
 * @author Gaollard
 */
'use strict';

const Controller = require('egg').Controller;

class CheckinController extends Controller {
  // 登录
  async login() {
    const { third_id, app_id } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.chat.login({ third_id, app_id });
  }

  // 获取聊天列表
  async getChatList() {
    const { user_id } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.chat.getChatList({ user_id });
  }

  // 获取聊天列表
  async getChatList2() {
    const { user_id } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.chat.getChatList2({ user_id });
  }

  // 获取历史消息
  async getHistory() {
    let {
      s_user,
      r_user,
      pageSize,
      pageIndex,
      is_group,
      room_id
    } = this.ctx.request.body;

    pageSize = pageSize || 10;
    pageIndex = pageIndex || 1;

    this.ctx.body = await this.ctx.service.chat.getHistory({
      s_user,
      r_user,
      pageSize,
      pageIndex,
      is_group,
      room_id
    });
  }

  async show() {
    const { token } = this.ctx.request.query;
    const { partnerId } = this.ctx.params;
    const uid = await this.ctx.service.user.getUserIdByToken(token);
    this.ctx.body = await this.ctx.service.chat.show({ uid, partnerId });
  }

  // 用户搜索
  async searchUser() {
    const { searchKey } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.chat.searchUser({ searchKey });
  }

  // 获取好友申请通知列表
  async getNewFirentNotice() {
    const { user_id } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.friend.getNewFirentNotice({ user_id });
  }

  async getFriendList() {
    const { user_id } = this.ctx.request.body;
    this.ctx.body = await this.ctx.service.friend.getFriendList({ user_id }); 
  }
}

module.exports = CheckinController;


